#include "aed_entity.h"

AED_Entity::AED_Entity()
{
    m_arch = 0;

    m_pos_x = 0;
    m_pos_y = 0;
    m_rot = 0;
    m_size = 1;

    m_selected = false;
}

AED_Entity::AED_Entity(AED_Archtype *arch)
{
    SetArchtype(arch);

    m_pos_x = 0;
    m_pos_y = 0;
    m_rot = 0;
    m_size = 1;

    m_selected = false;
}

AED_Entity::AED_Entity(const AED_Entity &ent){
    m_pos_x = ent.m_pos_x;
    m_pos_y = ent.m_pos_y;
    m_rot = ent.m_rot;
    m_size = ent.m_size;

    o_pos_x = ent.o_pos_x;
    o_pos_y = ent.o_pos_y;
    o_rot = ent.o_rot;
    o_size = ent.o_size;
    o_alpha = ent.o_alpha;

    m_selected = ent.m_selected;

    SetArchtype(ent.m_arch);
}

AED_Entity & AED_Entity::operator=(const AED_Entity &ent){
    m_pos_x = ent.m_pos_x;
    m_pos_y = ent.m_pos_y;
    m_rot = ent.m_rot;
    m_size = ent.m_size;
    m_selected = ent.m_selected;

    o_pos_x = ent.o_pos_x;
    o_pos_y = ent.o_pos_y;
    o_rot = ent.o_rot;
    o_size = ent.o_size;
    o_alpha = ent.o_alpha;

    SetArchtype(ent.m_arch);

    return *this;
}

AED_Archtype* AED_Entity::GetArchtype(){
    return m_arch;
}

void AED_Entity::SetArchtype(AED_Archtype *arch){
    m_arch = arch;
}

void AED_Entity::Save(QTextStream &file){
    file << "<entity>" << endl;
    file << "   <name = " << m_arch->GetName() << ">" << endl;
    file << "   <pos_x = " << m_pos_x << ">" << endl;
    file << "   <pos_y = " << m_pos_y << ">" << endl;
    file << "   <rot = " << m_rot << ">" << endl;
    file << "   <size = " << m_size << ">" << endl;
    file << "</entity>"<<endl<<endl<<endl;
}

void AED_Entity::Save(QDomDocument &doc, QDomElement &header){
    QDomElement elem = doc.createElement("entity");
    elem.setAttribute("name",m_arch->GetName());
    elem.setAttribute("pos_x",m_pos_x);
    elem.setAttribute("pos_y",m_pos_y);
    elem.setAttribute("rot",m_rot);
    elem.setAttribute("size",m_size);
    header.appendChild(elem);
}
